﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UIAStudio
{
    public class CSClass
    {
        private string _name;
        private string _parent;
        private List<string> _members = new List<string>();
        private List<string> _methods = new List<string>();
        private List<string> _properties = new List<string>();

        public CSClass(string name)
            : this(name, null)
        {
        }

        public CSClass(string name, string parent)
        {
            _name = name;
            _parent = parent;
        }

        public void AddMemberVariable(string statement)
        {
            _members.Add(statement);
        }

        public void AddMethod(string statement)
        {
            _methods.Add(statement);
        }

        public void AddProperty(string statement)
        {
            _properties.Add(statement);
        }

        public override string ToString()
        {
            StringBuilder code = new StringBuilder();
            StringBuilder memberSnippet = new StringBuilder();
            StringBuilder propertySnippet = new StringBuilder();
            StringBuilder methodSnippet = new StringBuilder();

            foreach(string member in _members)
            {
                memberSnippet.AppendLine(member);
            }
            foreach(string prop in _properties)
            {
                propertySnippet.AppendLine(prop);
                propertySnippet.AppendLine();
            }
            int len = propertySnippet.Length;
            propertySnippet = propertySnippet.Remove(len - 1, 1);   //remove last line.
            foreach (string method in _methods)
            {
                methodSnippet.AppendLine(method);
                methodSnippet.AppendLine();
            }
            len = methodSnippet.Length;
            methodSnippet = methodSnippet.Remove(len - 1, 1);   //remove last line.

            

            if (_parent == null)    //class head
            {
                code.AppendLine(String.Format("public class {0}", _name));
            }
            else
            {
                code.AppendLine(String.Format("public class {0} : {1}", _name, _parent));
            }
            code.AppendLine("{");
            code.AppendLine(memberSnippet.ToString());
            code.AppendLine();
            code.AppendLine(methodSnippet.ToString());
            code.AppendLine();
            code.AppendLine(propertySnippet.ToString());
            code.AppendLine("}");

            
            //string code = String.Format("public class {0}\r\n{\r\n{1}\r\n\r\n{
            return base.ToString();
        }
    }
}
